import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate"

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        flarr: [],
        token: "",
        name: "",
        user_id: "",
        cartarr: 0,
    },
    mutations: {
        fladd(state, arr) {
            state.flarr = arr
        },
        dladd(state, item) {
            state.token = item.token;
            state.user_id = item.obj
            console.log(state.token)
            console.log(state.user_id)
        },
        dlname(state, item) {
            state.name = item
        },
        tcdl(state) {
            state.token = ""
            state.user_id = ""
        },
        cartnum(state, item) {
            state.cartarr = item
        }
    },
    actions: {},
    modules: {},
    getters: {
        allnum(state) {
            let num = 0;
            state.cartarr.forEach((item) => {
                num += item.num
            })
            return num
        }
    },
    plugins: [createPersistedState()]
})